package engine.systems.render.render
{
	import ash.core.Component;
	import ash.core.Entity;
	
	import engine.utils.DisplayUtils;
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	
	import org.osflash.signals.Signal;

	public class Render extends Component
	{
		public var locked:Boolean = false;
		
		internal var _invalidate:Boolean = false;
		internal var _display:DisplayObject;
		
		public var changed:Signal = new Signal(Entity);
		
		public var visible:Boolean 	= true;
		public var remove:Boolean 	= true;
		
		public function Render(display:DisplayObject, container:DisplayObjectContainer = null, index:int = -1)
		{
			this._display = display;
			DisplayUtils.setIndex(display, container, index);
		}
		
		override public function destroy():void
		{
			this.changed.removeAll();
			this.changed = null;
			
			if(this.remove) DisplayUtils.destroy(this._display);
			this._display = null;
		}
		
		public function toString():String
		{
			return "[Render: Name=" + display.name + "]";
		}
		
		public function get display():DisplayObject { return this._display; }
		public function set display(display:DisplayObject):void
		{
			if(this._display == display) return;
			
			this._display 		= display;
			this._invalidate 	= true;
		}
	}
}